{extend name="base"/}
{block name="title"}
注册
{/block}
{block name="css"}
<link rel="stylesheet" href="__MOBILE__/css/registered.css"/>

{/block}
{block name="content"}
    <div class="header">
        <div class="fanhui">
            <a href="javascript:history.go(-1);"><img src="__MOBILE__/images/fanhui.png" alt=""></a>
        </div>
        注册账号
    </div>
    <div class="regInfo">
        <ul>
            <li>
                <img src="__MOBILE__/images/yonghuming.png" alt="">
                <input type="text" placeholder="请输入用户名" class="username">
            </li>
            <li>
                <img src="__MOBILE__/images/shoujihao.png" alt="">
                <input type="text" placeholder="请输入手机号" class="usertell">
            </li>
            <li>
                <img src="__MOBILE__/images/yanzhengma.png" alt="">
                <input type="text" placeholder="请输入验证码" class="usercode">
                <p class="getCode">获取验证码</p>
            </li>
            <li>
                <img src="__MOBILE__/images/mima.png" alt="">
                <input type="password" placeholder="密码" class="userpass">
            </li>
            <li>
                <img src="__MOBILE__/images/mima.png" alt="">
                <input type="password" placeholder="交易密码" class="userpassword">
            </li>
            <li>
                <img src="__MOBILE__/images/yaoqingma.png" alt="">
                <input type="text" placeholder="邀请码" class="userinvite" {if condition="$mobile != null"} disabled="disabled" value="{$mobile}" {else /} value="" {/if}>
            </li>
        </ul>
    </div>
    <div class="regButton">注册</div>
    <div class="gotoLogin"><a href="{:url('/langjinmobile/registered/login')}">已有账号，去登录</a> </div>
{/block}

{block name="js"}

<script>
    $('.regButton').click(function(){

        if($('.username').val()== ''){
            msg_alert('请输入您的用户名')
        }else if($('.usertell').val()== ''){
            msg_alert('请输入您的手机号')
        }else if($('.userpass').val()== ''){
            msg_alert('请输入您的密码')
        }else if($('.userpassword').val()== ''){
            msg_alert('请输入您的支付密码')
        }else if($('.userinvite').val()== ''){
            msg_alert('请输入邀请码')
        }else if($('.usercode').val()== ''){
            msg_alert('请输入验证码')
        }else{
            var username = $('.username').val();
            var usertell = $('.usertell').val();
            var userpass = $('.userpass').val();
            var userpassword = $('.userpassword').val();
            var userinvite = $('.userinvite').val();
            var usercode = $('.usercode').val();
            $.post("{:url('/langjinmobile/registered/doregister')}", {
                code: usercode,//验证码
                phone: usertell,//手机号
                pwd: userpass,//密码
                parent_id: userinvite,//邀请人手机号
                nickname: username,//昵称
                safety_pwd: userpassword//支付密码
                // verify: verify
            }, function (data) {
                console.log(data);
                if (data.code == 1) {
                    msg_alert(data.msg, data.url);
                } else {
                    msg_alert(data.msg);
                }
            })
        }
    })
    $('.getCode').click(function(){
        var username = $('.username').val();
            var userpass = $('.userpass').val();
            var userpassword = $('.userpassword').val();
            var userinvite = $('.userinvite').val();
            var usercode = $('.usercode').val();
            var usertell = $('.usertell').val();
        var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
        if($('.usertell').val()== '' || !myreg.test(usertell)){
            msg_alert('请输入正确的手机号')
                return
        }
        
        if($('.username').val()== ''){
            msg_alert('请输入昵称')
                return
        }
        if($(this).text() =='获取验证码'){
            $.post("{:url('/langjinmobile/registered/code')}", {
                        mobile: usertell
                    }, function (data) {
                        console.log(data);
                        if (data == 1) {
                            var obj = $("#mycode");
                            settime();
                            layer.msg("发送成功");
                        } else if (data == 5) {
                            layer.msg("{:lang('该手机号已经注册')}");

                        }
                    })

            
        }
    })


    function settime(){
        msg_alert('验证码已发送，请注意查收')
            var num = 60;
        var _this = $('.getCode');
        var timer = setInterval(function() {
            num--
            _this.text(num + 'S');
            if(num == 0){
                _this.text('获取验证码');
                clearInterval(timer);
            }
        },1000)
    }
</script>
{/block}